use std::collections::BTreeMap;

use rustc_serialize::json::Json;
use rustc_serialize::json::ToJson;

#[derive(Debug, PartialEq, Eq)]
pub struct Student {
    username: String,
    phone: i64,
    grade: i64,
    school: String,
}

impl Student {
    pub fn new(username: String, phone: i64, grade: i64, school: String) -> Student {
        Student {
            username: username.to_string(),
            phone: phone,
            grade: grade,
            school: school.to_string()
        }
    }
}

impl ToJson for Student {
    fn to_json(&self) -> Json {
        let mut map = BTreeMap::new();
        map.insert("username".to_string(), self.username.to_json());
        map.insert("phone".to_string(), self.phone.to_json());
        map.insert("grade".to_string(), self.grade.to_json());
        map.insert("school".to_string(), self.school.to_json());
        Json::Object(map)
    }
}
